package org.example.xtcs.anpes2;

import com.google.auto.service.AutoService;
import org.example.util.AsmUtils;
import org.example.xtcs.annotate.Xtcs;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;

/**
 * @ClassName: CustomAnnotationProcessor
 * @Description:
 * @Author: YourName
 * @Date: 2024/12/18
 */

@SupportedAnnotationTypes("org.example.xtcs.annotate.Xtcs")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@AutoService(Processor.class)
public class XtcsAnnotationProcessor2 extends AbstractProcessor {
    java.util.List<String> fieldNames = new ArrayList<>(Arrays.asList("XTCS1", "XTCS2", "XTCS3"));

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

        for (Element element : roundEnv.getElementsAnnotatedWith(Xtcs.class)) {

            String className = element.getSimpleName().toString();
            System.out.println("==============ASM 开始修改类===========`");
            //获取全限定名
            String qualifiedName = element.getEnclosingElement().toString();
            System.out.println(qualifiedName+"."+className);

            try {
                AsmUtils.testModifyCalss(qualifiedName+"."+className);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }


        }
        return true;
    }
}
